package com.xuecheng.openfeign.config;


import com.xuecheng.common.entity.utils.UserContext;
import com.xuecheng.openfeign.fallback.ItemClientFallbackFactory;
import feign.Logger;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.context.annotation.Bean;

public class DefaultFeignConfig {

    @Bean
    public Logger.Level feignLoggerLevel(){
        return Logger.Level.FULL;
    }

    @Bean
    public RequestInterceptor requestInterceptor(){
        return new RequestInterceptor() {
            @Override
            public void apply(RequestTemplate requestTemplate) {
                requestTemplate.header("user-info", UserContext.getUser().toString());
            }
        };
    }

    //失败降级处理
    @Bean
    public ItemClientFallbackFactory itemClientFallbackFactory(){
        return new ItemClientFallbackFactory();
    }



}
